/*
 * Copyright (c) 2018. czmc All Rights Reserved.
 * Author: czmc
 * Email: zxc6355533@163.com
 * Encoding: UTF-8
 */

package top.stime21.myneighbours.module.topic

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import cn.bingoogolapple.bgabanner.BGABanner
import kotlinx.android.synthetic.main.layout_header.view.*
import top.stime21.myneighbours.R
import top.stime21.myneighbours.utils.ImageLoader
import java.util.*

/**
 * Author: czmc  Email: zxc6355533@163.com
 * Version:	1.0  Date:2018/3/2
 */

class TopicAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private var context: Context? = null

    constructor(context: Context) {
        this.context = context;
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder?, position: Int) {
        if(getItemViewType(position)==1){
            (holder as HeaderViewHolder).setData(Arrays.asList("http://ofpu6opxd.bkt.clouddn.com/image/0/1479964264398.JPG", "http://ofpu6opxd.bkt.clouddn.com/image/0/1479963924329.jpg", "http://ofpu6opxd.bkt.clouddn.com/image/0/1479963924329.jpg"), Arrays.asList("提示文字1", "提示文字2", "提示文字3"))
        }
    }

    override fun getItemCount(): Int {
        return 10
    }

    override fun getItemViewType(position: Int): Int {
        if (position == 0) return 1
        return 2
    }

    override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): RecyclerView.ViewHolder {
        if (viewType == 1)
            return HeaderViewHolder(LayoutInflater.from(context!!).inflate(R.layout.layout_header, parent, false))
        else
            return ItemViewHolder(LayoutInflater.from(context!!).inflate(R.layout.item_topic, parent, false))
    }

    class ItemViewHolder(itemView: View?) : RecyclerView.ViewHolder(itemView) {

    }

    class HeaderViewHolder : RecyclerView.ViewHolder {
        constructor(itemView: View?) : super(itemView) {
            itemView!!.banner_guide_content.setAdapter(BGABanner.Adapter<ImageView?, String> { banner, itemView, model, position ->
                ImageLoader().load(model!!, itemView)
            })
        }
        fun setData(imgs:List<String>,title:List<String>){
            itemView!!.banner_guide_content.setData(imgs,title)
        }
    }

//

}